/* ======================================================= */
/**
 * File   : DrawPanel.java
 * Date   : 3 mars 2010 at 08:31:46
 */
/* ======================================================= */
package fr.isima.isipaint.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

import fr.isima.isipaint.model.GraphicGroup;
import fr.isima.isipaint.model.GraphicObject;

/* ======================================================= */
/**
 * 
 * @author Daniel Represent the scene. It's the area to draw GraphicObjects
 * 
 */
/* ======================================================= */
public class DrawPanel extends JPanel {

	/** Serial Version for serialization */
	private static final long serialVersionUID = 1L;

	/** The "root" group with object groups drawed */
	private GraphicGroup scene;
	
	/** The current object */
	private GraphicObject current;

	/**
	 * @return the current
	 */
	public final GraphicObject getCurrent() {
		return current;
	}

	/**
	 * @param current the current to set
	 */
	public final void setCurrent(GraphicObject current) {
		this.current = current;
	}

	/* ======================================================= */
	/**
	 * Default constructor
	 * 
	 */
	/* ======================================================= */
	public DrawPanel(GraphicGroup scene, GraphicObject current) {
		this.scene = scene;
		this.current = current;
		setBackground(Color.WHITE);		
	}

	/* ======================================================= */
	/**
	 * Called to draw all of the scene
	 * 
	 * @param g
	 *            The graphic to be able to draw graphic objects
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	/* ======================================================= */
	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		super.paintComponent(g);
		for (GraphicObject object : scene.getGroup()) {
			object.draw(g2);
		}

	}

}
